package nl.boektrust.btsoep.client;

import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public abstract class EditBookVerticalPanelAddLink extends EditBookVerticalPanel implements BlurHandler,  ValueChangeHandler<String>, ClickHandler {
	Label secondLabel = new Label();
	EditBookDialog parentDialog;
	//String value;


	public EditBookVerticalPanelAddLink(String label, EditBookDialog parentDialog) {
		super(label);	
		secondLabel.setText("voeg toe...");
		theLabel.setText("voeg toe...");
		secondLabel.addClickHandler(this);	
		theLabel.addClickHandler(this);	
		editPanel.add(secondLabel);
		this.parentDialog = parentDialog;
		setToDisplayMode();
	}

	public EditBookVerticalPanelAddLink() {
		this("", null);
	}
	

	@Override void setToEditMode() {
		super.setToEditMode();
	}
	
	/**
	 * @return the value
	 */
	public String getValue() {
		return (String)value;
	}

	/**
	 * @param value the value to set
	 */
	public void setValue(String value) {
		super.value = value;
		if (theLabel == null) System.err.println("EditBookVerticalPanelAddLink:setValue(): theLabel is null");
		if (value == null) System.err.println("EditBookVerticalPanelAddLink:setValue(): the value is null");
		if (value.length() > 0)	{
			theLabel.setText(value);
		}

	}

	public void onValueChange(ValueChangeEvent<String> event) {
		setToDisplayMode();
	}

	

	// if the edit element loses focus, set to display mode. 
	public void onBlur(BlurEvent event) {
		setToDisplayMode();
	}
	
	public abstract  void addLinkClicked();

	public void onClick(ClickEvent event) {
		this.addLinkClicked();
		if (parentDialog != null) parentDialog.panelHasChanged();
		// TODO Auto-generated method stub
		
		
	}

}
